<!DOCTYPE html>
<html>
   <head>
      <title>
            <?php if($type == "add"):?>
                中骏森驰人员去向登记
            <?php elseif ($type == "show"):?>
                中骏人员去向列表
            <?php endif;?>
      </title>
      <meta name="viewport" content="width=device-width, initial-scale=1.0 Access-Control-Allow-Origin">
      <!-- 引入 Bootstrap -->
      <!--<link href="<?=base_url('html/bootstrap_v3/css/bootstrap.css')?>" rel="stylesheet">-->
      <link href="<?=  base_url('/html/bootstrap_v3/css/bootstrap.css')?>" rel="stylesheet">
      <link href="<?=base_url('html/bootstrap_v3/datepicker/css/bootstrap-datetimepicker.min.css')?>" rel="stylesheet">
      <link href="<?=base_url('html/css/bootstrap_list.css')?>" rel="stylesheet">
      <script src="<?=base_url('html/js/jquery-1.8.3.min.js')?>"></script>
      <script src="<?=base_url('html/bootstrap_v3/js/bootstrap.min.js')?>"></script>
      <script src="<?=base_url('html/bootstrap_v3/datepicker/js/bootstrap-datetimepicker.js')?>"></script>
      <script src="<?=base_url('html/bootstrap_v3/datepicker/js/locales/bootstrap-datetimepicker.zh-CN.js')?>"></script>
      <script>
      $('.goDate').datetimepicker({
        language: 'zh-CN',
        weekStart: 1,
        todayBtn: 1,
        autoclose: 1,
        todayHighlight: 1,
        startView: 2,
        forceParse: 0,
        showMeridian: 1
      });
      </script>
      <!-- HTML5 Shim 和 Respond.js 用于让 IE8 支持 HTML5元素和媒体查询 -->
      <!-- 注意： 如果通过 file://  引入 Respond.js 文件，则该文件无法起效果 -->
      <!--[if lt IE 9]>
         <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
         <script src="https://oss.maxcdn.com/libs/respond.js/1.3.0/respond.min.js"></script>
      <![endif]-->
   </head>
   <body>
        
        <?php if($type == "add"):?>
            <div class="container">
            <div class="form-horizontal" style="padding-left: 8px;padding-right: 8px">
                    <legend class="text-center" style="font-weight:bold;font-size:2em;">
                        人员去向管理
                    </legend>
                    <div class="form-group">
                        <label for="username" class="control-label col-xs-3 col-sm-2">
                            员工姓名
                        </label>
                        <div class="input-group col-xs-9 col-sm-10">
                            <input type="text" class="form-control" id="username" readonly="readonly" value="<?=$username?>"/>
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="userid" class="control-label col-xs-3 col-sm-2">
                            员工工号
                        </label>
                        <div class="input-group col-xs-9 col-sm-10">
                            <input type="text" class="form-control" id="userid" readonly="readonly" value="<?=$userid?>"/>
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="leavetype" class="control-label col-xs-3 col-sm-2">
                            离开类型
                        </label>
                        <div class="col-xs-9 col-sm-10 input-group" id="leavetype">
                            <div class="radio">
                                <label>
                                    <input type="radio" name="leavetype" value="请假" checked> 请假
                                </label>
                            </div>
                            <div class="radio">
                                <label>
                                    <input type="radio" name="leavetype" value="公出"> 公出
                                </label>
                            </div>
                            <!--
                            <select class="form-control" id="leavetype_val">
                                <option value="请假">请假</option>
                                <option value="拜访客户">拜访客户</option>
                                <option value="车间现场">车间现场</option>
                            </select>
                            -->
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="remark" class="control-label col-xs-3 col-sm-2">
                            备注
                        </label>
                        <div class="input-group col-xs-9 col-sm-10">
                            <textarea class="form-control" rows="2" id="remark"></textarea>
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="departuretime" class="control-label col-xs-3 col-sm-2">
                            离开时间
                        </label>
                        <div class="input-group col-xs-9 col-sm-10 date departuretime" data-date="" data-date-format="yyyy/mm/dd - HH:ii p" data-link-field="departuretime">
                            <input class="form-control" size="16" id="departuretime" type="text" value="" readonly>
                            <span class="input-group-addon">
                                <span class="glyphicon glyphicon-th">
                                </span>
                            </span>
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="backtime" class="control-label col-xs-3 col-sm-2">
                            返回时间
                        </label>
                        <div class="input-group col-xs-9 col-sm-10 date backtime" data-date="" data-date-format="yyyy/mm/dd - HH:ii p" data-link-field="backtime">
                            <input class="form-control" size="16" id="backtime" type="text" value="" readonly>
                            <span class="input-group-addon">
                                <span class="glyphicon glyphicon-th">
                                </span>
                            </span>
                        </div>
                    </div>
                    <div>
                        <button type="button" class="btn btn-primary btn-lg btn-block" onclick="nextCheck()">提   交</button>
                    </div>
                    <button style="display:none" type="button" class="btn btn-primary btn-lg btn-block" data-toggle="modal" data-target="#myModal" id="next">
                        提交
                    </button>
                    <!-- 模态框（Modal） -->
                    <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
                        <div class="modal-dialog">
                            <div class="modal-content">
                                <div class="modal-header">
                                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                                    <h4 class="modal-title" id="myModalLabel">提交确认</h4>
                                </div>
                                <div class="modal-body">请确认你的人员去向信息内容，如确认无误请提交！</div>
                                <div class="modal-footer">
                                    <button type="button" class="btn btn-default" data-dismiss="modal">返回</button>
                                    <button type="button" class="btn btn-primary" id="submit">提交</button>
                                </div>
                            </div><!-- /.modal-content -->
                        </div><!-- /.modal-dialog -->
                    </div>
                    <!-- /.modal -->
                </div>
            </div>
        <?php elseif ($type == "list"):?>
            <ul class="list-group" >
                <?php foreach ($data as $value):?>
                <a class="list-group-item" href="<?=  base_url('PersonCheck/judgeUser?ID=').$value["ID"].'&Uid='.$Uid?>">
                        <h4 class="list-group-item-heading"><?=$value['USERNAME']?> - <?=$value['LEAVETYPE']?></h4><span class="glyphicon glyphicon-chevron-right" style="float: right;"></span>
                        <p class="list-group-item-text"><?=$value['REMARK']?></p>
                        <p class="list-group-item-text">归期：<?=$value['BACKTIME']?></p>
                    </a>
                <?php endforeach;?>
                <!--
                <a class="list-group-item">
                    <h4 class="list-group-item-heading">列表1标题</h4>
                    <span class="badge">111</span>
                    <p class="list-group-item-text">列表1内容列表1内容列表1内容列表1内容列表1内容列表1内容列表1内容列表1内容列表1内容</p>
                </a>
                <a class="list-group-item" href="#">
                    <h4 class="list-group-item-heading">列表2标题</h4>
                    <span class="glyphicon glyphicon-chevron-right" style="float: right;"></span>
                    <p class="list-group-item-text">列表2内容列表2内容列表2内容列表2内容列表2内容列表2内容列表2内容列表2内容列表2内容列表2内容列表2内容列表2内容</p>
                </a>
                -->
            </ul>
        <?php elseif($type == "show"):?>
            <div class="container">
            <div class="form-horizontal" style="padding-left: 8px;padding-right: 8px">
                    <legend class="text-center" style="font-weight:bold;font-size:2em;">
                        人员去向管理
                    </legend>
                    <div class="form-group">
                        <label for="username" class="control-label col-xs-3 col-sm-2">
                            员工姓名
                        </label>
                        <div class="input-group col-xs-9 col-sm-10">
                            <input type="text" class="form-control" id="username" readonly="readonly" value="<?=$data['USERNAME']?>"/>
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="userid" class="control-label col-xs-3 col-sm-2">
                            员工工号
                        </label>
                        <div class="input-group col-xs-9 col-sm-10">
                            <input type="text" class="form-control" id="userid" readonly="readonly" value="<?=$data['USERID']?>"/>
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="leavetype" class="control-label col-xs-3 col-sm-2">
                            离开类型
                        </label>
                        <div class="col-xs-9 col-sm-10 input-group" id="leavetype">
                            <div class="radio">
                                <label>
                                    <input type="radio" name="leavetype" value="请假" <?php if($data['LEAVETYPE'] == "请假"):?>checked<?php endif;?>> 请假
                                </label>
                            </div>
                            <div class="radio">
                                <label>
                                    <input type="radio" name="leavetype" value="公出" <?php if($data['LEAVETYPE'] == "公出"):?>checked<?php endif;?>> 公出
                                </label>
                            </div>
                            <!--
                            <select class="form-control" id="leavetype_val">
                                <option value="请假">请假</option>
                                <option value="拜访客户">拜访客户</option>
                                <option value="车间现场">车间现场</option>
                            </select>
                            -->
                        </div>
                    </div>
                    <script>
                        $("input[name='leavetype']").each(function(){
                            if($(this).attr('checked') === false){
                                $(this).attr("disabled","disabled");
                            }
                        })
                    </script>
                    <div class="form-group">
                        <label for="remark" class="control-label col-xs-3 col-sm-2">
                            备注
                        </label>
                        <div class="input-group col-xs-9 col-sm-10">
                            <textarea class="form-control" rows="2" id="remark" readonly="readonly"><?=$data["REMARK"]?></textarea>
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="departuretime" class="control-label col-xs-3 col-sm-2">
                            离开时间
                        </label>
                        <div class="input-group col-xs-9 col-sm-10">
                            <input class="form-control" size="16" id="" type="text" value="<?=$data['DEPARTURETIME']?>" readonly>
                            <!--
                            <span class="input-group-addon">
                                <span class="glyphicon glyphicon-th">
                                </span>
                            </span>
                            -->
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="backtime" class="control-label col-xs-3 col-sm-2">
                            返回时间
                        </label>
                        <div class="input-group col-xs-9 col-sm-10">
                            <input class="form-control" size="16" id="" type="text" value="<?=$data['BACKTIME']?>" readonly>
                            <!--
                            <span class="input-group-addon">
                                <span class="glyphicon glyphicon-th">
                                </span>
                            </span>
                            -->
                        </div>
                    </div>
                    <div>
                        <button type="button" class="btn btn-primary btn-lg btn-block" onclick="back()">返回</button>
                    </div>
                <!--
                    <div>
                        <button type="button" class="btn btn-primary btn-lg btn-block" onclick="nextCheck()">提   交</button>
                    </div>
                -->
                </div>
            </div>
        <?php elseif($type == "edit"):?>
            <div class="container">
            <div class="form-horizontal" style="padding-left: 8px;padding-right: 8px">
                    <legend class="text-center" style="font-weight:bold;font-size:2em;">
                        人员去向管理
                    </legend>
                    <div class="form-group">
                        <label for="username" class="control-label col-xs-3 col-sm-2">
                            员工姓名
                        </label>
                        <div class="input-group col-xs-9 col-sm-10">
                            <input type="text" class="form-control" id="username" readonly="readonly" value="<?=$data['USERNAME']?>"/>
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="userid" class="control-label col-xs-3 col-sm-2">
                            员工工号
                        </label>
                        <div class="input-group col-xs-9 col-sm-10">
                            <input type="text" class="form-control" id="userid" readonly="readonly" value="<?=$data["USERID"]?>"/>
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="leavetype" class="control-label col-xs-3 col-sm-2">
                            离开类型
                        </label>
                        <div class="col-xs-9 col-sm-10 input-group" id="leavetype">
                            <div class="radio">
                                <label>
                                    <input type="radio" name="leavetype" value="请假" <?php if($data['LEAVETYPE'] == "请假"):?>checked<?php endif;?>> 请假
                                </label>
                            </div>
                            <div class="radio">
                                <label>
                                    <input type="radio" name="leavetype" value="公出" <?php if($data['LEAVETYPE'] == "公出"):?>checked<?php endif;?>> 公出
                                </label>
                            </div>
                            <!--
                            <select class="form-control" id="leavetype_val">
                                <option value="请假">请假</option>
                                <option value="拜访客户">拜访客户</option>
                                <option value="车间现场">车间现场</option>
                            </select>
                            -->
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="remark" class="control-label col-xs-3 col-sm-2">
                            备注
                        </label>
                        <div class="input-group col-xs-9 col-sm-10">
                            <textarea class="form-control" rows="2" id="remark" value='<?=$data["REMARK"]?>'></textarea>
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="departuretime" class="control-label col-xs-3 col-sm-2">
                            离开时间
                        </label>
                        <div class="input-group col-xs-9 col-sm-10 date departuretime" data-date="" data-date-format="yyyy/mm/dd - HH:ii p" data-link-field="departuretime">
                            <input class="form-control" size="16" id="departuretime" type="text" value="<?=$data['DEPARTURETIME']?>" readonly>
                            <span class="input-group-addon">
                                <span class="glyphicon glyphicon-th">
                                </span>
                            </span>
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="backtime" class="control-label col-xs-3 col-sm-2">
                            返回时间
                        </label>
                        <div class="input-group col-xs-9 col-sm-10 date backtime" data-date="" data-date-format="yyyy/mm/dd - HH:ii p" data-link-field="backtime">
                            <input class="form-control" size="16" id="backtime" type="text" value="<?=$data['BACKTIME']?>" readonly>
                            <span class="input-group-addon">
                                <span class="glyphicon glyphicon-th">
                                </span>
                            </span>
                        </div>
                    </div>
                    <div>
                        <button type="button" class="btn btn-primary btn-lg btn-block" onclick="editCheck()">修    改</button>
                    </div>
                    <button style="display:none" type="button" class="btn btn-primary btn-lg btn-block" data-toggle="modal" data-target="#myModalEdit" id="edit">
                        提交
                    </button>
                    <!-- 模态框（Modal） -->
                    <div class="modal fade" id="myModalEdit" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
                        <div class="modal-dialog">
                            <div class="modal-content">
                                <div class="modal-header">
                                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                                    <h4 class="modal-title" id="myModalLabel">修改确认</h4>
                                </div>
                                <div class="modal-body">请确认你的人员去向信息内容，如确认修改无误请点击修改！</div>
                                <div class="modal-footer">
                                    <button type="button" class="btn btn-default" data-dismiss="modal">返回</button>
                                    <button type="button" class="btn btn-primary" id="submit">修改</button>
                                </div>
                            </div><!-- /.modal-content -->
                        </div><!-- /.modal-dialog -->
                    </div>
                    <!-- /.modal -->
                </div>
            </div>
        <?php endif;?>
            
    <script type="text/javascript">
        $('.departuretime').datetimepicker({
        language: 'zh-CN',
        weekStart: 1,
        todayBtn: 1,
        autoclose: 1,
        todayHighlight: 1,
        startView: 2,
        forceParse: 0,
        showMeridian: 1,
	 format:'yyyy-mm-dd H:i:s'
        }).on('changeDate',
	function(ev){
		var start = $("#departuretime").val();
		var end   = $("#backtime").val();
		if(end.length>0){
			if(start>end){
				$("#departuretime").val("");
				alert("错误：开始时间晚于结束时间！请检查！");
			}
		}
	});
        $('.backtime').datetimepicker({
            language: 'zh-CN',
            weekStart: 1,
            todayBtn: 1,
            autoclose: 1,
            todayHighlight: 1,
            startView: 2,
            forceParse: 0,
            showMeridian: 1
        }).on('changeDate',
	function(ev){
            var start = $("#departuretime").val();
            var end   = $("#backtime").val();
            if(start.length>0){
                    if(start>end){
                            $("#backtime").val("");
                            alert("错误：结束时间早于开始时间！请检查！");
                    }
            }
	});
     function nextCheck(){
         var departuretime = $("#departuretime").val();
         var backtime      = $("#backtime").val();
         var errmsg = "";
         if(departuretime == ""){
             errmsg += "请选择离开时间！\n";
         }
         if(backtime == ""){
             errmsg += "请选择返回时间";
         }
         if(errmsg.length > 0){
             alert(errmsg);
         }else{
             $("#next").click();
         }
         
     }
     
     function back(){
         window.location.href = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxd2b4ceb62757c00c&redirect_uri=<?=base_url()?>/PersonCheck/Login_List&response_type=code&scope=snsapi_base&state=STATEs#wechat_redirect";
     }
     
     function editCheck(){
         var departuretime = $("#departuretime").val();
         var backtime      = $("#backtime").val();
         var errmsg = "";
         if(departuretime == ""){
             errmsg += "请选择离开时间！\n";
         }
         if(backtime == ""){
             errmsg += "请选择返回时间";
         }
         if(errmsg.length > 0){
             alert(errmsg);
         }else{
             $("#edit").click();
         }
         
     }
     
     $("#submit").one("click",function(){
         var userid        = $("#userid").val();
         var username      = $("#username").val();
         var leavetype     = $('#leavetype input[name="leavetype"]:checked ').val();
         var remark        = $("#remark").val();
         var departuretime = $("#departuretime").val();
         var backtime      = $("#backtime").val();
         $.ajax({
             type:"POST",
             url:"<?=  base_url('PersonCheck/addData')?>",
             data:{userid:userid,
                    username:username,
                    leavetype:leavetype,
                    remark:remark,
                    departuretime:departuretime,
                    backtime:backtime},
             success:function(data){
                    //window.setTimeout("window.location='<?=  base_url("PersonCheck/getOutList")?>'",3000); 
                    alert("外出去向信息提交成功！");
                    window.location.href = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxd2b4ceb62757c00c&redirect_uri=<?=base_url()?>/PersonCheck/Login_List&response_type=code&scope=snsapi_base&state=STATEs#wechat_redirect";
                    //go(3,"<?=  base_url('PersonCheck/getOutList')?>");
             }
             
         });
     })
     /*
    function go(t, url) {
        //t设置跳转时间：秒     
        //url设置跳转网址    
        document.write("<div id=text>本页将在<strong id='tt'>3</strong>后，跳转至：<span id='link'></span></div>");
        document.getElementById("link").innerHTML = "<a href=" + url + ">" + url + "</a>";
        $(t, url);
    }
    
    function $(t, url) {
        //ta = t - 1;
        //tb = t + "000";
        //d = document.getElementById("tt");
        //d.innerHTML = t;

        window.setInterval(function() {
            go_to(url);
        },
        1000);
    }
    
    function go_to(url) {
        //d.innerHTML = ta--;
        if (ta < 0) {
            document.write("正在跳转至：<a href=" + url + ">" + url + "</a>");
            location.href = url;
        } else {
            return;
        }
    }
    */
    </script>
   </body>
</html>